package org.nanotek.tika.tests;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.tika.io.TikaInputStream;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.apache.tika.mime.MimeTypes;
import org.apache.tools.ant.DirectoryScanner;

public class MediaTypeTest {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		DirectoryScanner scanner = new DirectoryScanner();  
		scanner.setIncludes(new String[]{"**\\*.*"});  
		scanner.setBasedir("F:\\java\\Lucene4\\MetadataIndexer\\src");  
		scanner.setCaseSensitive(false);  
		scanner.scan();
		String[] files = scanner.getIncludedFiles(); 
		MimeTypes mt = new MimeTypes(); 
		for (String fileStr : files) 
		{
			File file = new File(scanner.getBasedir() + System.getProperty("file.separator") + fileStr);
			System.out.println(file.toString());
			InputStream input =  TikaInputStream.get(new FileInputStream(file)); 
			MediaType mtd = mt.detect(input, new Metadata());
			System.out.println(mtd.toString());
		}
	}

}
